from address_normalizer.app import create_app
from address_normalizer.app.config import CHINA_REGIONS_JSON, PATTERN_FILE, logger, EXCEL_FILE, PROVINCE_CITY_DISTRICT, \
    JIEBA_FILE, DEFAULT_FREQUENCY, HTTP_HOST, HTTP_PORT
from address_normalizer.app.utils.conversion import convert_regions_to_patterns, process_and_save_area_data, \
    create_jieba_dict, load_data_from_json

app = create_app()

if __name__ == "__main__":
    logger.info("启动服务!")
    process_and_save_area_data(EXCEL_FILE, PROVINCE_CITY_DISTRICT, CHINA_REGIONS_JSON)
    convert_regions_to_patterns(CHINA_REGIONS_JSON, PATTERN_FILE)
    create_jieba_dict(load_data_from_json(PATTERN_FILE), output_file=JIEBA_FILE, default_frequency=DEFAULT_FREQUENCY)
    logger.info("文件更新完成！")
    app.run(host=HTTP_HOST, port=HTTP_PORT, debug=True)
